package com.yj.spring.charpter02;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Iterator;

public class ClassPathXmlResource implements Resource {

    Document document;
    Element root;

    Iterator iterator;

    public ClassPathXmlResource(String path) {
        SAXReader reader = new SAXReader();
        try {
            document = reader.read(this.getClass().getClassLoader().getResource(path));
            root = document.getRootElement();
            iterator = root.elementIterator();
        }catch (Exception e){
            e.printStackTrace();
        }
    }



    @Override
    public boolean hasNext() {
        return iterator.hasNext();
    }

    @Override
    public Object next() {
        return iterator.next();
    }
}
